package com.jt.controller;

import com.jt.pojo.User2;
import com.jt.service.User2Service;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author tang
 * @data 2021/9/4
 * @apiNode
 */
@RestController
@RequestMapping("/users")
@CrossOrigin
public class User2Controller {
    @Autowired
    private User2Service user2Service;

    @GetMapping("/getAll")
    public List<User2> getAll(){
        return user2Service.getAll();
    }

    @DeleteMapping("/deleteuser/{id}")
    public SysResult deleteUser(@PathVariable Integer id){
        user2Service.deleteUserById(id);
        return SysResult.success();
    }

    @GetMapping("/getById/{id}")
    public SysResult getById(@PathVariable Integer id){
        User2 user2 = user2Service.getById(id);
        return SysResult.success(user2);
    }

    @PutMapping("/updateUser")
    public SysResult updateUser(@RequestBody User2 user2){
        user2Service.updateUser(user2);
        return SysResult.success();
    }

    @PostMapping("/saveUser")
    public SysResult saveUser(@RequestBody User2 user2){
        user2Service.saveUser(user2);
        return SysResult.success();
    }

    @PutMapping("/userStutas/{id}/{status}")
    public SysResult updateStutas(User2 user2){
        user2Service.updateStutas(user2);
        return SysResult.success();
    }
}
